﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.App;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;
namespace HKEA.CMS.Core.BLL.App
{
    public class app_tblCust_BranchBLL
    {
        private Iapp_tblCust_Branch IDAL;

        public app_tblCust_BranchBLL()
        {
            IDAL = DataAccess.CreateIapp_tblCust_Branch();
        }


        /// <summary>
        /// 插入一条记录，返回当前记录的UID ； 并非影响行数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(app_tblCust_Branch ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.InsertENT(ent);
                }
                catch (Exception er)
                {
                    throw;
                }
            }
            return ret;
        }

        public List<M_BranchListDetail> GetListByCustUID(int custUID)
        {
            List<M_BranchListDetail> list = new List<M_BranchListDetail>();
            if (custUID > 0)
            {
                try { list = IDAL.GetListByCustUID(custUID); }
                catch (Exception er) { throw; }
            }
            return list;
        }

        public app_tblCust_Branch GetEntity(app_tblCust_Branch ent, bool IsAddDeleteForSelect)
        {
            var list = GetListByENT(ent, IsAddDeleteForSelect);
            if(list!=null)
                return list.FirstOrDefault();
            return null;
        }

        public List<app_tblCust_Branch> GetListByENT(app_tblCust_Branch ent, bool IsAddDeleteForSelect)
        {
            List<app_tblCust_Branch> list = new List<app_tblCust_Branch>();
            if (ent != null)
            {
                try { list = IDAL.GetListByENT(ent, IsAddDeleteForSelect); }
                catch (Exception er)
                { throw; }
            }
            return list;
        }
        public int UpdateENT(app_tblCust_Branch ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception er)
                { throw; }
            }
            return ret;
        }
        public int DeleteENT(app_tblCust_Branch ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception er)
                { throw; }
            }
            return ret;
        }
        public List<int> GetCustomerUIDList()
        {
            try { return IDAL.GetCustomerUIDList(); }
            catch (Exception er) { }
            return null;
        }
    }
}
